home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-01-23 | 2.0 KB | 96 lines | [TEXT/MPS ] |
- {$R-}
- {
- WhichLine -- an XFNC to find the line of a given character. Used when there is
- a need to know on which line a given character falls.
-
- Programmer -- D. Jay Newman
- Date -- 1/23/89
-
- This XFNC expects two parameters:
- 1 A piece of text to find.
-
- 2 A container which contains text in which the first parameter lies.
-
- The return value is the line number in which the first string is found. If the
- first string is not found, then the return value is 0.
-
- It should be used like:
- put WhichLine ("some text", theText) into it
- }
-
- {$S WhichLine } { Segment name must be the same as the command name. }
-
- UNIT AnyUnit;
-
- INTERFACE
-
- USES MemTypes, QuickDraw, OSIntf, HyperXCmd;
-
- PROCEDURE ENTRYPOINT(paramPtr: XCmdPtr);
-
-
- IMPLEMENTATION
-
-
- CONST
- kComma = Ord (',');
- kZero = Ord ('0');
- kReturn = 13;
-
- kNameSize = 40;
- kIDSize = 6;
-
- TYPE
- Str31 = String[31];
-
-
- PROCEDURE WhichLine (paramPtr: XCmdPtr); FORWARD;
-
- PROCEDURE ENTRYPOINT(paramPtr: XCmdPtr);
- BEGIN
- WhichLine (paramPtr);
- END;
-
-
-
- {This is the main program}
- PROCEDURE WhichLine (paramPtr: XCmdPtr);
- VAR
- p: Ptr; {String to search for}
- theText: Ptr; {String in which to search}
- s: Str255; {Pattern string}
- numLines: INTEGER; {Number of lines}
-
- {$I XCmdGlue.inc }
-
- BEGIN
- WITH paramPtr^ DO
- BEGIN
- IF paramCount < 2 THEN EXIT (WhichLine);
-
- HLock (params [1]); {lock so we can take pointer}
- ZeroToPas (params[1]^, s); {get pascal string}
- HUnlock (params [1]); {unlock like a good boy}
-
- HLock (params [2]); {Lock the search text and take ptr}
- theText := params [2]^;
-
- p := StringMatch (s, theText);
-
- numLines := 0;
- IF p <> NIL THEN
- BEGIN
- WHILE Ord4 (p) >= Ord4 (theText) DO
- BEGIN
- numLines := numLines + 1;
- ScanToReturn (theText);
- theText := Ptr (Ord4 (theText) + 1);
- END;
- END;
-
- HUnlock (params[2]); {Unlock like a good boy}
- returnValue := PasToZero (NumToStr (numLines));
- END;
- END; {WhichLine}
-
- END.